
<?php include_once(dirname(__FILE__) . '/../general/head.php'); ?>

<!-- header -->
<?php include_once(dirname(__FILE__) . '/../general/header.php'); ?>

<?php include_once('left.php'); ?>


<div id="page-wrapper">


    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">Báo cáo performance cuối cùng</h1>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <div class="row">
        <div class="col-lg-12">
            <div class="panel-group" id="accordion">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">Thống kê</a>
                        </h4>
                    </div>
                    <div id="collapseOne" class="panel-collapse collapse in">
                        <div class="col-lg-6">
                            <script type="text/javascript" src="https://www.google.com/jsapi"></script>
                            <script type="text/javascript">
                                google.load("visualization", "1.0", {'packages': ['corechart']});
                                google.setOnLoadCallback(drawChart);
                                function drawChart() {
                                    var data = google.visualization.arrayToDataTable(<?php echo $chartData; ?>);

                                    var options = {
                                        title: '',
                                        legend: 'none',
                                        hAxis: {title: '', titleTextStyle: {color: 'red'}}
                                    };

                                    var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
                                    chart.draw(data, options);
                                }
                            </script>

                            <div id="chart_div"></div>
                        </div>
                        <div class="col-lg-6">
                            <div class="panel-body">
                                <table class="table table-bordered table-hover table-striped">
                                    <tr>
                                        <td><?php echo color_final_results('Need Improvement'); ?></td>
                                        <td><?php echo $ni . ' / ' . count($rows); ?></td>
                                    </tr>
                                    <tr>
                                        <td><?php echo color_final_results('Becoming Effective'); ?></td>
                                        <td><?php echo $be . ' / ' . count($rows); ?></td>
                                    </tr>
                                    <tr>
                                        <td><?php echo color_final_results('Effective'); ?></td>
                                        <td><?php echo $ef . ' / ' . count($rows); ?></td>
                                    </tr>
                                    <tr>
                                        <td><?php echo color_final_results('High Effective'); ?></td>
                                        <td><?php echo $he . ' / ' . count($rows); ?></td>
                                    </tr>
                                    <tr>
                                        <td><?php echo color_final_results('Exceptional'); ?></td>
                                        <td><?php echo $ex . ' / ' . count($rows); ?></td>
                                    </tr>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    Danh sách
                </div>
                <!-- /.panel-heading -->
                <div class="panel-body">



                    <div class="col-lg-6">
                        Supervisor 
                        <select class="form-control display-inline" name="filter-ss" style="width: 200px;">
                            <option value="all">Tất cả</option>
                            <?php foreach ($supervisors as $eachSS) { ?>
                                <option value="<?php echo $eachSS['code']; ?>" <?php echo ($filterSS == $eachSS['code']) ? 'selected="selected"' : ''; ?>><?php echo $eachSS['name']; ?></option>
                            <?php } ?>
                        </select>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        Nhóm
                        <select class="form-control display-inline" name="filter-title" style="width: 100px;">
                            <option value="all">Tất cả</option>
                            <?php
                            foreach ($titles as $key => $value) {
                                ?>
                                <option value="<?php echo $value; ?>" <?php echo ($filterTitle == $value) ? 'selected="selected"' : ''; ?>><?php echo $key; ?></option>
                            <?php } ?>
                        </select>
                        <br><br>
                    </div>


                    <div class="col-lg-12">
                        <?php if ($rows == false || count($rows) == 0) { ?>
                            Hiện tại không có kết quả nào!
                            <br>
                        <?php } else { ?>
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover" id="final-results">
                                    <thead>
                                        <tr>
                                            <th>TL code</th>
                                            <th>SS code</th>
                                            <th>RSM code</th>
                                            <!--<th width="40px">No</th>-->

                                            <th width="90px">Area</th>
                                            <th width="110px">Location</th>
                                            <th width="70px">Mã NV</th>
                                            <th width="50px">Title</th>
                                            <th>Họ và tên</th>

                                            <th width="100px">Kết quả <br> trắc nghiệm</th>
                                            <th width="110px">Kết quả <br> sale performance</th>
                                            <th>Kết quả ban đầu</th>
                                            <th>Kết quả thái độ</th>
                                            <th>Kết quả cuối cùng</th>
        <!--                                        <th>&nbsp;</th>-->
                                        </tr>
                                    </thead>
                                    <tbody>

                                        <?php
                                        $i = 1;
                                        foreach ($rows as $row) {
                                            ?>
                                            <tr>
                                                <td><?php echo $row['teamleader_code']; ?></td>
                                                <td><?php echo $row['supervisor_code']; ?></td>
                                                <td><?php echo $row['rsm_code']; ?></td>
                                                <!--<td><?php echo $i; ?></td>-->

                                                <td><?php echo $regionDic[$row['rsm_code']]; ?></td>
                                                <td><?php echo $row['location']; ?></td>
                                                <td><?php echo $row['code']; ?></td>
                                                <td><?php echo $row['title']; ?></td>
                                                <td><?php echo $row['name']; ?></td>

                                                <td><?php echo ($row['testResult']['percentage']) ? number_format($row['testResult']['percentage'], 2, '.', '') . '%' : ''; ?></td>
                                                <td><?php echo $row['saleResult']['score']; ?></td>
                                                <td><?php echo color_final_results($row['firstRating']['name']); ?> </td>
                                                <td><?php echo color_attitude($row['attResult']['score'], $settings['att_high_score'], $settings['att_medium_score'], $row['attResult']['rating']); ?></td>
                                                <td><?php echo color_final_results($row['finalRating']['name']); ?> </td>
            <!--                                            <td>
                                                            <a href="<?php echo site_url(get_folder($loggedUser['title']) . '/quizzes/attempt/' . $row->quid); ?>">Attempt</a>

                                                    <a href="javascript: if(confirm('Bạn có chắc là muốn xóa không?')){ window.location='<?php echo site_url(get_folder($loggedUser['title']) . '/quizzes/remove_quiz/' . $row->quid); ?>'; }"><img src="<?php echo base_url(); ?>images/cross.png" title="Remove"></a> <a href="<?php echo site_url(get_folder($loggedUser['title']) . '/quizzes/edit_quiz/' . $row->quid); ?>"><img src="<?php echo base_url(); ?>images/edit.png" title="Edit"></a>

                                                </td>-->
                                            </tr>
                                            <?php
                                            $i++;
                                        }
                                        ?>
                                    </tbody>
                                </table>
                            </div>
                        <?php } ?>
                    </div>
                    <br>
<!--                    <a href="<?php echo site_url(get_folder($loggedUser['title']) . '/quizzes/add_new'); ?>"> <img src="<?php echo base_url(); ?>images/plus.png" title="Thêm bài test mới"> Thêm bài test mới</a>
                    <br>-->
                </div>
                <!-- /.panel-body -->
            </div>
        </div>
    </div>

</div>
<!-- /#page-wrapper -->
<!--<script type="text/javascript" src="<?php echo base_url(); ?>js/filter-region-title.js"></script>-->
<script>
    function search()
    {
        var region = "";
        var title = "";

        $("select[name=filter-ss] option:selected").each(function() {
            region = $(this).val();
        });
        $("select[name=filter-title] option:selected").each(function() {
            title = $(this).val();
        });
        window.location = '<?php echo site_url(get_folder($loggedUser['title']) . '/final_results/index') ?>' + '/' + region + '/' + title;
    }

    $(document).ready(function() {
        var oTable = $('#final-results').dataTable(
                {
                    "scrollX": true,
                    "sScrollX": "120%",
                    //"bScrollCollapse": true,
                    //"sScrollXInner": "110%",
                    //"bScrollAutoCss": true,
                    "columnDefs": [
                        {
                            "targets": [0],
                            "visible": false,
                            "searchable": false,
                            "orderData": [0, 1]
                        },
                        {
                            "targets": [1],
                            "visible": false,
                            "searchable": false,
                            "orderData": [0, 1]
                        },
                        {
                            "targets": [2],
                            "visible": false,
                            "searchable": false,
                            "orderData": [0, 1]
                        }
                    ]
                }
        );

        $('select[name=filter-ss]').change(function() {
            search();
        });

        $('select[name=filter-title]').change(function() {
            search();
        });



    });

</script>
<?php include_once(dirname(__FILE__) . '/../general/footer.php'); ?>